﻿Imports System.Web.UI.WebControls
Imports HBBSoft.Pivot
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Partial Class Demo_Demo
    Inherits System.Web.UI.Page

    Private ConnectionString As String

#Region "**************各种演示报表**************"

#Region "-------------------综合演示报表------------------------------"
    Private Sub ShowReport_1()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Product
            objRowDim = CreateDimension()
            objRowDim.SingleColumn = True
            objRowDim.Caption = "Product"
            objRowDim.Name = "Product"
            objRowDim.Hierarchy = "Product Categories"
            objRowDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)


            'Sales Territory
            objRowDim = CreateDimension()
            objRowDim.Caption = "Sales Territory"
            objRowDim.Name = "Sales Territory"
            objRowDim.Hierarchy = "Sales Territory"
            objRowDim.AllMember.UniqueName = "[Sales Territory].[Sales Territory].[All Sales Territories]"

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Group"
            objLevel.Caption = "Group"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Country"
            objLevel.Caption = "Country"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Region"
            objLevel.Caption = "Region"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)

            '--------------------------ColDimensionTree----------------------------------
            'Fiscal Date
            objColDim = CreateDimension()
            objColDim.Caption = "Fiscal Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Fiscal"
            objColDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Fiscal Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Fiscal Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            CreateMeasures()

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.SingleSelect = True
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            .FilterDimensions.Add(objfilterdim)

            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.SubMDXForWith = GetMyMeasuresMDX()
            ds.CellForeColor = True
            ds.CellBackColor = True
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
            .ShowEmptyCols = True
            .ShowEmptyRows = True
        End With
    End Sub

    Private Sub CreateMeasures()
        With ept.PivotTable
            .DataSet.CellSets.Clear()

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Value"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(1).Measures.Add(CreateMeasure)
            .DataSet.CellSets(1).Measures(0).Name = "Value"
            .DataSet.CellSets(1).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Name = "Status"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Caption = "Status"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Status)

            .DataSet.CellSets(1).Measures.Add(CreateMeasure)
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).Name = "Status"
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).Caption = "Status"
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Status)

            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Name = "Trend"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Caption = "Trend"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Trend)

            .DataSet.CellSets(1).Measures.Add(CreateMeasure)
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).Name = "Trend"
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).Caption = "Trend"
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Trend)

            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Name = "Percent"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Caption = "Percent"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Percent)

            .DataSet.CellSets(1).Measures.Add(CreateMeasure)
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).Name = "Percent"
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).Caption = "Percent"
            .DataSet.CellSets(1).Measures(.DataSet.CellSets(1).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Percent)
        End With
    End Sub

    Private Function GetMyMeasuresMDX() As String
        Dim mdx As String = ""

        mdx &= "Member [Measures].[Value] as '[Measures].[Sales Amount]',"
        mdx &= "                              Format_String='#,#.00',"
        mdx &= "                              Fore_Color='iif([Measures].[Status]=-1,255,iif([Measures].[Status]=1,16711680 ,null))',"
        mdx &= "                              Back_Color='iif([Measures].[Trend]=-1,11992830,iif([Measures].[Trend]=1,12910535,null))'"
        mdx &= "Member [Measures].[Goal] as 'Case"
        mdx &= "									When IsEmpty"
        mdx &= "										 ("
        mdx &= "										   ParallelPeriod"
        mdx &= "										   ("
        mdx &= "											 [Date].[Fiscal].[Fiscal Year],"
        mdx &= "											 1,"
        mdx &= "											 [Date].[Fiscal].CurrentMember"
        mdx &= "										   )"
        mdx &= "										 )"
        mdx &= "									Then [Measures].[Sales Amount]              "
        mdx &= "									Else 1.15 *"
        mdx &= "										 ( "
        mdx &= "										   [Measures].[Sales Amount],"
        mdx &= "										   ParallelPeriod"
        mdx &= "										   ("
        mdx &= "											 [Date].[Fiscal].[Fiscal Year],"
        mdx &= "											 1,"
        mdx &= "											 [Date].[Fiscal].CurrentMember"
        mdx &= "										   )"
        mdx &= "										 )"
        mdx &= "								End'"
        mdx &= "Member [Measures].[Status] as 'Case"
        mdx &= "									When [Measures].[Value] / [Measures].[Goal] >  1"
        mdx &= "									Then 1"
        mdx &= "									When [Measures].[Value] / [Measures].[Goal] <= 1"
        mdx &= "										 And "
        mdx &= "										 [Measures].[Value] / [Measures].[Goal] >= .85"
        mdx &= "									Then 0"
        mdx &= "									Else -1"
        mdx &= "								End'"
        mdx &= "Member [Measures].[Trend] as 'Case"
        mdx &= "								When IsEmpty"
        mdx &= "									 ("
        mdx &= "									   ParallelPeriod"
        mdx &= "									   ("
        mdx &= "										 [Date].[Fiscal].[Fiscal Year],"
        mdx &= "										 1,"
        mdx &= "										 [Date].[Fiscal].CurrentMember"
        mdx &= "									   )"
        mdx &= "									 )"
        mdx &= "								Then 0  "
        mdx &= "								When VBA!Abs"
        mdx &= "									 ("
        mdx &= "									  ( "
        mdx &= "										[Measures].[Value] "
        mdx &= "										- "
        mdx &= "										("
        mdx &= "										  [Measures].[Value],"
        mdx &= "										  ParallelPeriod"
        mdx &= "										  ( "
        mdx &= "											[Date].[Fiscal].[Fiscal Year],"
        mdx &= "											1,"
        mdx &= "											[Date].[Fiscal].CurrentMember"
        mdx &= "										  )"
        mdx &= "										)"
        mdx &= "									  ) "
        mdx &= "									  /"
        mdx &= "									  ("
        mdx &= "										[Measures].[Value],"
        mdx &= "										ParallelPeriod"
        mdx &= "										( "
        mdx &= "										  [Date].[Fiscal].[Fiscal Year],"
        mdx &= "										  1,"
        mdx &= "										  [Date].[Fiscal].CurrentMember"
        mdx &= "										)"
        mdx &= "									  )  "
        mdx &= "									 ) <=.02"
        mdx &= "								Then 0"
        mdx &= "								When ( "
        mdx &= "									   [Measures].[Value] "
        mdx &= "									   - "
        mdx &= "									   ("
        mdx &= "										 [Measures].[Value],"
        mdx &= "										 ParallelPeriod"
        mdx &= "										 ( "
        mdx &= "										   [Date].[Fiscal].[Fiscal Year],"
        mdx &= "										   1,"
        mdx &= "										   [Date].[Fiscal].CurrentMember"
        mdx &= "										 )"
        mdx &= "									   ) "
        mdx &= "									 )"
        mdx &= "									 /"
        mdx &= "									 ("
        mdx &= "									   [Measures].[Value],"
        mdx &= "									   ParallelPeriod"
        mdx &= "									   ( "
        mdx &= "										 [Date].[Fiscal].[Fiscal Year],"
        mdx &= "										 1,"
        mdx &= "										 [Date].[Fiscal].CurrentMember"
        mdx &= "									   )"
        mdx &= "									 ) >.02"
        mdx &= "								Then 1"
        mdx &= "								Else -1"
        mdx &= "							End'"
        mdx &= "Member [Measures].[Percent] as '[Measures].[Sales Amount]/([Date].[Fiscal].CurrentMember.Parent,[Measures].[Sales Amount])*100'"

        Return mdx
    End Function

    Private Function CreateMeasureDisplayModel_Status() As MeasureDisplayModel_Image
        Dim dmImage As New MeasureDisplayModel_Image

        dmImage.Segments.Add(CreateSegment(-1, EnumBeginValueCompareModel.emBiggishAndEqual, -1, EnumEndValueCompareModel.emLesserAndEqual, "Images\Status-1.gif"))
        dmImage.Segments.Add(CreateSegment(0, EnumBeginValueCompareModel.emBiggishAndEqual, 0, EnumEndValueCompareModel.emLesserAndEqual, "Images\Status0.gif"))
        dmImage.Segments.Add(CreateSegment(1, EnumBeginValueCompareModel.emBiggishAndEqual, 1, EnumEndValueCompareModel.emLesserAndEqual, "Images\Status1.gif"))

        Return dmImage
    End Function

    Private Function CreateMeasureDisplayModel_Trend() As MeasureDisplayModel_Image
        Dim dmImage As New MeasureDisplayModel_Image

        dmImage.Segments.Add(CreateSegment(-1, EnumBeginValueCompareModel.emBiggishAndEqual, -1, EnumEndValueCompareModel.emLesserAndEqual, "Images\Trend-1.gif"))
        dmImage.Segments.Add(CreateSegment(0, EnumBeginValueCompareModel.emBiggishAndEqual, 0, EnumEndValueCompareModel.emLesserAndEqual, "Images\Trend0.gif"))
        dmImage.Segments.Add(CreateSegment(1, EnumBeginValueCompareModel.emBiggishAndEqual, 1, EnumEndValueCompareModel.emLesserAndEqual, "Images\Trend1.gif"))

        Return dmImage
    End Function

    Private Function CreateMeasureDisplayModel_Percent() As MeasureDisplayModel_Image
        Dim dmImage As New MeasureDisplayModel_Image
        Dim i As Integer

        dmImage.DefaultImageURL = "Images\Percent.gif"

        dmImage.Segments.Add(CreateSegment(-200000000, EnumBeginValueCompareModel.emBiggish, 0, EnumEndValueCompareModel.emLesserAndEqual, "Images\Percent.gif"))

        For i = 1 To 99
            dmImage.Segments.Add(CreateSegment(i - 1, EnumBeginValueCompareModel.emBiggish, i, EnumEndValueCompareModel.emLesserAndEqual, "Images\Percent" & i & ".gif"))
        Next

        dmImage.Segments.Add(CreateSegment(99, EnumBeginValueCompareModel.emBiggish, 200000000, EnumEndValueCompareModel.emLesserAndEqual, "Images\Percent100.gif"))

        Return dmImage
    End Function
#End Region

#Region "-------------------简单报表----------------------------------"
    Private Sub ShowReport_2()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Product
            objRowDim = CreateDimension()
            objRowDim.Caption = "Product"
            objRowDim.Name = "Product"
            objRowDim.Hierarchy = "Product Categories"
            objRowDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)


            '--------------------------ColDimensionTree----------------------------------
            'Fiscal Date
            objColDim = CreateDimension()
            objColDim.Caption = "Fiscal Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Fiscal"
            objColDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Fiscal Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Fiscal Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()
            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension


            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Territory"
            objfilterdim.Name = "Sales Territory"
            objfilterdim.Hierarchy = "Sales Territory"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            objfilterdim.SingleSelect = True
            .FilterDimensions.Add(objfilterdim)

            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
        End With
    End Sub
#End Region

#Region "-------------------行维度单列缩进----------------------------"
    Private Sub ShowReport_3()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Fiscal Date
            objRowDim = CreateDimension()
            objRowDim.SingleColumn = True
            objRowDim.Caption = "Date"
            objRowDim.Name = "Date"
            objRowDim.Hierarchy = "Fiscal"
            objRowDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Year"
            objLevel.InitExpandedMember = CreateMember()
            objLevel.InitExpandedMember.UniqueName = "[Date].[Fiscal].[Fiscal Year].members(0)"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Semester"
            objLevel.InitExpandedMember = CreateMember()
            objLevel.InitExpandedMember.UniqueName = "[Date].[Fiscal].[Fiscal Semester].members(0)"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Quarter"
            objLevel.InitExpandedMember = CreateMember()
            objLevel.InitExpandedMember.UniqueName = "[Date].[Fiscal].[Fiscal Quarter].members(0)"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)

            '--------------------------ColDimensionTree----------------------------------
            'Product
            objColDim = CreateDimension()
            objColDim.SingleColumn = True
            objColDim.Caption = "Product"
            objColDim.Name = "Product"
            objColDim.Hierarchy = "Product Categories"
            objColDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()
            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension


            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Territory"
            objfilterdim.Name = "Sales Territory"
            objfilterdim.Hierarchy = "Sales Territory"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            objfilterdim.SingleSelect = True
            .FilterDimensions.Add(objfilterdim)
            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
        End With
    End Sub
#End Region

#Region "-------------------动态前背景颜色----------------------------"
    Private Sub ShowReport_4()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Product
            objRowDim = CreateDimension()
            objRowDim.SingleColumn = True
            objRowDim.Caption = "Product"
            objRowDim.Name = "Product"
            objRowDim.Hierarchy = "Product Categories"
            objRowDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)


            '--------------------------ColDimensionTree----------------------------------
            'Fiscal Date
            objColDim = CreateDimension()
            objColDim.Caption = "Fiscal Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Fiscal"
            objColDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Fiscal Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Fiscal Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()
            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Value"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension


            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Territory"
            objfilterdim.Name = "Sales Territory"
            objfilterdim.Hierarchy = "Sales Territory"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            objfilterdim.SingleSelect = True
            .FilterDimensions.Add(objfilterdim)
            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.SubMDXForWith = GetMyMeasuresMDX()
            ds.CellForeColor = True
            ds.CellBackColor = True
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
        End With
    End Sub
#End Region

#Region "-------------------图表--------------------------------------"
    Private Sub ShowReport_5()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Product
            objRowDim = CreateDimension()
            objRowDim.SingleColumn = True
            objRowDim.Caption = "Product"
            objRowDim.Name = "Product"
            objRowDim.Hierarchy = "Product Categories"
            objRowDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)

            '--------------------------ColDimensionTree----------------------------------
            'Fiscal Date
            objColDim = CreateDimension()
            objColDim.Caption = "Fiscal Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Fiscal"
            objColDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Fiscal Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Fiscal Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Value"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Name = "Percent"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Caption = "Percent"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Percent)


            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension


            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Territory"
            objfilterdim.Name = "Sales Territory"
            objfilterdim.Hierarchy = "Sales Territory"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            objfilterdim.SingleSelect = True
            .FilterDimensions.Add(objfilterdim)
            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.SubMDXForWith = GetMyMeasuresMDX()
            ds.CellForeColor = False
            ds.CellBackColor = False
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
        End With
    End Sub
#End Region

#Region "-------------------KPI报表----------------------------------"
    Private Sub ShowReport_6()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Fiscal Date
            objRowDim = CreateDimension()
            objRowDim.Caption = "Date"
            objRowDim.Name = "Date"
            objRowDim.Hierarchy = "Fiscal"
            objRowDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Year"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Semester"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Quarter"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)

            '--------------------------ColDimensionTree----------------------------------
            'Product
            objColDim = CreateDimension()
            objColDim.Caption = "Product"
            objColDim.Name = "Product"
            objColDim.Hierarchy = "Product Categories"
            objColDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Value"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Name = "Status"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Caption = "Status"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Status)

            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Name = "Trend"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).Caption = "Trend"
            .DataSet.CellSets(0).Measures(.DataSet.CellSets(0).Measures.Count - 1).DisplayModels.Add(CreateMeasureDisplayModel_Trend)

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension


            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Territory"
            objfilterdim.Name = "Sales Territory"
            objfilterdim.Hierarchy = "Sales Territory"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            objfilterdim.SingleSelect = True
            .FilterDimensions.Add(objfilterdim)
            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.SubMDXForWith = GetMyMeasuresMDX()
            ds.CellForeColor = False
            ds.CellBackColor = False
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
        End With
    End Sub
#End Region

#Region "-------------------合计优先----------------------------------"
    Private Sub ShowReport_7()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Product
            objRowDim = CreateDimension()
            objRowDim.Beforetotal = True
            objRowDim.Caption = "Product"
            objRowDim.Name = "Product"
            objRowDim.Hierarchy = "Product Categories"
            objRowDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)


            '--------------------------ColDimensionTree----------------------------------
            'Fiscal Date
            objColDim = CreateDimension()
            objColDim.Beforetotal = True
            objColDim.Caption = "Fiscal Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Fiscal"
            objColDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Fiscal Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Fiscal Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()
            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Territory"
            objfilterdim.Name = "Sales Territory"
            objfilterdim.Hierarchy = "Sales Territory"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            objfilterdim.SingleSelect = True
            .FilterDimensions.Add(objfilterdim)
            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
        End With

    End Sub
#End Region

#Region "-------------------多个透视----------------------------------"
    Private Sub ShowReport_8()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Product
            objRowDim = CreateDimension()
            objRowDim.SingleColumn = True
            objRowDim.Caption = "Product"
            objRowDim.Name = "Product"
            objRowDim.Hierarchy = "Product Categories"
            objRowDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)


            'Sales Territory
            objRowDim = CreateDimension()
            objRowDim.Caption = "Sales Territory"
            objRowDim.Name = "Sales Territory"
            objRowDim.Hierarchy = "Sales Territory"
            objRowDim.AllMember.UniqueName = "[Sales Territory].[Sales Territory].[All Sales Territories]"

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Group"
            objLevel.Caption = "Group"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Country"
            objLevel.Caption = "Country"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Region"
            objLevel.Caption = "Region"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)

            'Employee
            'objRowDim = CreateDimension()
            'objRowDim.Caption = "Employee"
            'objRowDim.Name = "Employee"
            'objRowDim.Hierarchy = "Employees"
            'objRowDim.AllMember.UniqueName = "[Employee].[Employees].[All Employees]"

            'objLevel = CreateLevel()
            'objLevel.Name = "Employee Level 02"
            'objLevel.Caption = "Employee Level 02"
            'objRowDim.Levels.Add(objLevel)

            'objLevel = CreateLevel()
            'objLevel.Name = "Employee Level 03"
            'objLevel.Caption = "Employee Level 03"
            'objRowDim.Levels.Add(objLevel)

            'objLevel = CreateLevel()
            'objLevel.Name = "Employee Level 05"
            'objLevel.Caption = "Employee Level 05"
            'objRowDim.Levels.Add(objLevel)

            '.RowDimensionTree.Dimensions.Add(objRowDim)

            '--------------------------ColDimensionTree----------------------------------
            'Fiscal Date
            objColDim = CreateDimension()
            objColDim.Caption = "Fiscal Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Fiscal"
            objColDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Semester"
            objLevel.Caption = "Fiscal Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Quarter"
            objLevel.Caption = "Fiscal Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            'Calendar Date
            objColDim = CreateDimension()
            objColDim.SingleColumn = True
            objColDim.Caption = "Calendar Date"
            objColDim.Name = "Date"
            objColDim.Hierarchy = "Calendar"
            objColDim.AllMember.UniqueName = "[Date].[Calendar].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Calendar Year"
            objLevel.Caption = "Calendar Year"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Calendar Semester"
            objLevel.Caption = "Calendar Semester"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Calendar Quarter"
            objLevel.Caption = "Calendar Quarter"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(1).Measures.Add(CreateMeasure)
            .DataSet.CellSets(1).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(1).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(2).Measures.Add(CreateMeasure)
            .DataSet.CellSets(2).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(2).Measures(0).Caption = "Sales Amount"

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(3).Measures.Add(CreateMeasure)
            .DataSet.CellSets(3).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(3).Measures(0).Caption = "Sales Amount"

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.SingleSelect = True
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            .FilterDimensions.Add(objfilterdim)

            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
            .ShowEmptyCols = True
            .ShowEmptyRows = True
        End With
    End Sub
#End Region

#Region "-------------------多层维度----------------------------------"
    Private Sub ShowReport_9()
        With ept.PivotTable
            Dim objLevel As Level
            Dim objRowDim As Dimension
            Dim objColDim As Dimension

            '--------------------------RowDimensionTree----------------------------------
            'Fiscal Date
            objRowDim = CreateDimension()
            objRowDim.Caption = "Fiscal Date"
            objRowDim.Name = "Date"
            objRowDim.Hierarchy = "Fiscal"
            objRowDim.AllMember.UniqueName = "[Date].[Fiscal].[All Periods]"

            objLevel = CreateLevel()
            objLevel.Name = "Fiscal Year"
            objLevel.Caption = "Fiscal Year"
            objLevel.InitExpandedMember = CreateMember()
            objLevel.InitExpandedMember.UniqueName = "[Date].[Fiscal].[Fiscal Year].members(0)"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Month"
            objLevel.Caption = "Month"
            objLevel.InitExpandedMember = CreateMember()
            objLevel.InitExpandedMember.UniqueName = "[Date].[Fiscal].[Month].members(0),[Date].[Fiscal].[Month].members(1)"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions.Add(objRowDim)

            'Sales Territory
            objRowDim = CreateDimension()
            objRowDim.Caption = "Sales Territory"
            objRowDim.Name = "Sales Territory"
            objRowDim.Hierarchy = "Sales Territory"
            objRowDim.AllMember.UniqueName = "[Sales Territory].[Sales Territory].[All Sales Territories]"

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Group"
            objLevel.Caption = "Group"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Country"
            objLevel.Caption = "Country"
            objRowDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Sales Territory Region"
            objLevel.Caption = "Region"
            objRowDim.Levels.Add(objLevel)

            .RowDimensionTree.Dimensions(0).Child = objRowDim

            '--------------------------ColDimensionTree----------------------------------
            'Product
            objColDim = CreateDimension()
            objColDim.Caption = "Product"
            objColDim.Name = "Product"
            objColDim.Hierarchy = "Product Categories"
            objColDim.AllMember.UniqueName = "[Product].[Product Categories].[All Products]"

            objLevel = CreateLevel()
            objLevel.Name = "Category"
            objLevel.Caption = "Category"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Subcategory"
            objLevel.Caption = "Subcategory"
            objColDim.Levels.Add(objLevel)

            objLevel = CreateLevel()
            objLevel.Name = "Product Name"
            objLevel.Caption = "Product"
            objColDim.Levels.Add(objLevel)

            .ColDimensionTree.Dimensions.Add(objColDim)

            '-------------------------Measures------------------------------
            .DataSet.CellSets.Clear()

            .DataSet.CellSets.Add(CreateCellSet)
            .DataSet.CellSets(0).Measures.Add(CreateMeasure)
            .DataSet.CellSets(0).Measures(0).Name = "Sales Amount"
            .DataSet.CellSets(0).Measures(0).Caption = "Sales Amount"

            '----------------------FilterDimensions------------------------------
            Dim objfilterdim As Dimension

            objfilterdim = CreateDimension()
            objfilterdim.Caption = "Sales Channel"
            objfilterdim.Name = "Sales Channel"
            objfilterdim.Hierarchy = "Sales Channel"
            .FilterDimensions.Add(objfilterdim)

            objfilterdim = CreateDimension()
            objfilterdim.SingleSelect = True
            objfilterdim.Caption = "Destination Currency"
            objfilterdim.Name = "Destination Currency"
            objfilterdim.Hierarchy = "Destination Currency Code"
            .FilterDimensions.Add(objfilterdim)

            '-----------------------DataSource------------------------------
            Dim ds As New AnalysisServiceDataSource
            ds.Name = "Adventure Works"
            ds.ConnectionString = ConnectionString
            .DataSource = ds

            '----------------------Others------------------------------
            .MeasuresPosition = EnumMeasuresPosition.emCol
            .ShowEmptyCols = True
            .ShowEmptyRows = True
        End With
    End Sub
#End Region


#End Region



    Protected Sub dlReport_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dlReport.SelectedIndexChanged
        dlState.Items.Clear()
        ept.PivotTable = Nothing
        ept.PivotTable = New PivotTable

        Select Case dlReport.SelectedValue
            Case 1
                ShowReport_1()
            Case 2
                ShowReport_2()
            Case 3
                ShowReport_3()
            Case 4
                ShowReport_4()
            Case 5
                ShowReport_5()
            Case 6
                ShowReport_6()
            Case 7
                ShowReport_7()
            Case 8
                ShowReport_8()
            Case 9
                ShowReport_9()
        End Select
        lblReportTitle.Text = "演示报表 －－ " & dlReport.SelectedItem.Text
        ept.DataBind()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ConnectionString = "Location=" & Page.MapPath("") & "\Data\Adventure Works.cub;Provider=msolap;"
        'ConnectionString = "Data Source=Localhost;Provider=msolap;Initial Catalog=Adventure Works DW"

        If Not Page.IsPostBack Then
            ShowReport_1()
            lblReportTitle.Text = "演示报表 －－ " & dlReport.SelectedItem.Text
        End If
    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        dlReport.Enabled = Not ept.FilterState
        ibnCross.Enabled = Not ept.FilterState
        ibnStatic.Enabled = Not ept.FilterState
        dlState.Enabled = Not ept.FilterState
        ibnSave.Enabled = Not ept.FilterState
        dlStyle.Enabled = Not ept.FilterState
    End Sub


    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        If Request.Form("dlStyle") Is Nothing Then
            Page.Theme = "General"
        Else
            Page.Theme = Request.Form("dlStyle").ToString()
        End If
    End Sub

    Protected Sub ibnCross_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibnCross.Click
        Dim objDimTree As DimensionTree
        objDimTree = ept.PivotTable.RowDimensionTree
        ept.PivotTable.RowDimensionTree = ept.PivotTable.ColDimensionTree
        ept.PivotTable.ColDimensionTree = objDimTree

        'If ept.PivotTable.MeasuresPosition = EnumMeasuresPosition.emCol Then
        '    ept.PivotTable.MeasuresPosition = EnumMeasuresPosition.emRow
        'Else
        '    ept.PivotTable.MeasuresPosition = EnumMeasuresPosition.emCol
        'End If

        ept.DataBind()
    End Sub

    Protected Sub ibnStatic_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibnStatic.Click
        ept.PivotTable.ActionEnabled = Not ept.PivotTable.ActionEnabled
        ept.DataBind()
    End Sub

    Protected Sub ibnSave_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibnSave.Click
        Dim dlItem As New ListItem
        dlItem.Text = "状态" & dlState.Items.Count
        dlItem.Value = "ViewState_" & dlItem.Text

        ept.PivotTable.ClearData()
        ViewState(dlItem.Value) = ept.PivotTable

        dlState.Items.Add(dlItem)
    End Sub

    Protected Sub dlState_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dlState.SelectedIndexChanged
        Dim blnAction As Boolean = ept.PivotTable.ActionEnabled
        ept.PivotTable = ViewState(dlState.SelectedValue)
        ept.PivotTable.ActionEnabled = blnAction
        ept.DataBind()
    End Sub
End Class
